package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DsCollegeMapper;
import com.ruoyi.system.domain.DsCollege;
import com.ruoyi.system.service.IDsCollegeService;

/**
 * 学院Service业务层处理
 *
 * @author tyro
 * @date 2025-03-30
 */
@Service
public class DsCollegeServiceImpl implements IDsCollegeService
{
    @Autowired
    private DsCollegeMapper dsCollegeMapper;

    /**
     * 查询学院
     *
     * @param collegeId 学院主键
     * @return 学院
     */
    @Override
    public DsCollege selectDsCollegeByCollegeId(Long collegeId)
    {
        return dsCollegeMapper.selectDsCollegeByCollegeId(collegeId);
    }

    /**
     * 查询学院列表
     *
     * @param dsCollege 学院
     * @return 学院
     */
    @Override
    public List<DsCollege> selectDsCollegeList(DsCollege dsCollege)
    {
        // 设置学院ID
        if (dsCollege.getCollegeId() == null) {
            dsCollege.setCollegeId(Long.valueOf(SecurityUtils.getLoginUser().getCollegeId()));
        }
        return dsCollegeMapper.selectDsCollegeList(dsCollege);
    }

    /**
     * 新增学院
     *
     * @param dsCollege 学院
     * @return 结果
     */
    @Override
    public int insertDsCollege(DsCollege dsCollege)
    {
        return dsCollegeMapper.insertDsCollege(dsCollege);
    }

    /**
     * 修改学院
     *
     * @param dsCollege 学院
     * @return 结果
     */
    @Override
    public int updateDsCollege(DsCollege dsCollege)
    {
        return dsCollegeMapper.updateDsCollege(dsCollege);
    }

    /**
     * 批量删除学院
     *
     * @param collegeIds 需要删除的学院主键
     * @return 结果
     */
    @Override
    public int deleteDsCollegeByCollegeIds(Long[] collegeIds)
    {
        for (Long collegeId : collegeIds) {
            //删除所有本学院相关信息
            dsCollegeMapper.deleteMajorByCollegeId(collegeId);
            dsCollegeMapper.deleteStudentByCollegeId(collegeId);
            dsCollegeMapper.deleteTeacherByCollegeId(collegeId);
            dsCollegeMapper.deleteClassByCollegeId(collegeId);
            dsCollegeMapper.deleteClasByCollegeId(collegeId);
            dsCollegeMapper.deleteClassStuByCollegeId(collegeId);
            dsCollegeMapper.deleteKzByCollegeId(collegeId);
            dsCollegeMapper.deleteLtByCollegeId(collegeId);
            dsCollegeMapper.deleteQuestionAnalysisByCollegeId(collegeId);
            dsCollegeMapper.deleteStudentProfileByCollegeId(collegeId);
            dsCollegeMapper.deleteXxByCollegeId(collegeId);
            dsCollegeMapper.deleteZskByCollegeId(collegeId);
        }
        return dsCollegeMapper.deleteDsCollegeByCollegeIds(collegeIds);
    }

    /**
     * 删除学院信息
     *
     * @param collegeId 学院主键
     * @return 结果
     */
    @Override
    public int deleteDsCollegeByCollegeId(Long collegeId)
    {
        return dsCollegeMapper.deleteDsCollegeByCollegeId(collegeId);
    }
}
